angular.module("app").controller("welcomeCtrl", ["$scope", "$http", "$timeout","org", function($scope, $http, $timeout,org) {
    $scope.orgCountVo = {};
    $scope.getMonthList = function (number) {
        var monList = [];
        var d = new Date();
        var currYear = d.getFullYear();
        var currMon = d.getMonth();  // 获取上一个月份数值，此处不需要+1
        for(var i = 0; i < number; i++){
            if(currMon < 10){
                monList.push("" + currYear + "-0" + currMon);
            }else{
                monList.push("" + currYear + "-" + currMon);
            }
            currMon -= 1; // 获取上一个月份
            if(currMon == 0){
                currYear -= 1;
                currMon = 12;
            }
        }
        return monList.sort();
    };

    // org.count({}, {test:1}, function (data) {
    //     if (data.statusCode == 0) {
    //         $scope.orgCountVo = data.data.orgCountVo;
    //         $scope.activityList = data.data.activityStr.split(",");
    //         $scope.timeList = data.data.timeStr.split(",");
    //         $scope.volunteerList = data.data.volunteerStr.split(",");
    //         var dataSource = [];
    //         $scope.getMonthList(12).forEach(function (item,index) {
    //             var obj = {};
    //             obj.Month = item;
    //             obj.volunteer = +$scope.volunteerList[index];
    //             obj.time = +$scope.timeList[index];
    //             obj.activity = +$scope.activityList[index];
    //             dataSource.push(obj);
    //         });
    //         $scope.volunteerChartConfig.dataSource = $scope.activityChartConfig.dataSource = $scope.timeChartConfig.dataSource = dataSource;
    //     } else {
    //         alert(data.statusMessage)
    //     }
    // });

    $scope.volunteerChartConfig = {
        bindingOptions: {
            dataSource: "volunteerChartConfig.dataSource"
        },
        dataSource:[],
        commonSeriesSettings: {
            argumentField: "Month",
            type: "line"
        },
        margin: {
            bottom: 20
        },
        argumentAxis: {
            valueMarginsEnabled: false,
            discreteAxisDivisionMode: "crossLabels",
            grid: {
                visible: true
            }
        },
        series: [
            { valueField: "volunteer", name: "志愿者(人)" }
        ],
        legend: {
            verticalAlignment: "bottom",
            horizontalAlignment: "center",
            itemTextPosition: "bottom"
        },
        title: {
            text: "志愿者增量图"
            // subtitle: {
            //     text: "(Millions of Tons, Oil Equivalent)"
            // }
        },
        tooltip: {
            enabled: true,
            customizeTooltip: function (arg) {
                return {
                    text: arg.valueText + "人"
                };
            }
        }
    };

    $scope.activityChartConfig = {
        bindingOptions: {
            dataSource: "activityChartConfig.dataSource"
        },
        dataSource:[],
        commonSeriesSettings: {
            argumentField: "Month",
            type: "line"
        },
        margin: {
            bottom: 20
        },
        argumentAxis: {
            valueMarginsEnabled: false,
            discreteAxisDivisionMode: "crossLabels",
            grid: {
                visible: true
            }
        },
        series: [
            { valueField: "activity", name: "活动(次)" }
        ],
        legend: {
            verticalAlignment: "bottom",
            horizontalAlignment: "center",
            itemTextPosition: "bottom"
        },
        title: {
            text: "活动增量图"
            // subtitle: {
            //     text: "(Millions of Tons, Oil Equivalent)"
            // }
        },
        tooltip: {
            enabled: true,
            customizeTooltip: function (arg) {
                return {
                    text: arg.valueText + "次"
                };
            }
        }
    };

    $scope.timeChartConfig = {
        bindingOptions: {
            dataSource: "timeChartConfig.dataSource"
        },
        dataSource:[],
        commonSeriesSettings: {
            argumentField: "Month",
            type: "line"
        },
        margin: {
            bottom: 20
        },
        argumentAxis: {
            valueMarginsEnabled: false,
            discreteAxisDivisionMode: "crossLabels",
            grid: {
                visible: true
            }
        },
        series: [
            { valueField: "time", name: "公益时间(分钟)" }
        ],
        legend: {
            verticalAlignment: "bottom",
            horizontalAlignment: "center",
            itemTextPosition: "bottom"
        },
        title: {
            text: "公益时间增量图"
            // subtitle: {
            //     text: "(Millions of Tons, Oil Equivalent)"
            // }
        },
        tooltip: {
            enabled: true,
            customizeTooltip: function (arg) {
                return {
                    text: arg.valueText + "分钟"
                };
            }
        }
    };
}]);
